package com.tudouji.project.produce.controller;

import java.util.List;

import com.tudouji.project.bill.domain.Whoutform;
import com.tudouji.project.produce.domain.Materialretapply;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.produce.domain.Scrapapply;
import com.tudouji.project.produce.service.IScrapapplyService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 报废单Controller
 * 
 * @author tudouji
 * @date 2022-06-01
 */
@RestController
@RequestMapping("/produce/scrapapply")
public class ScrapapplyController extends BaseController
{
    @Autowired
    private IScrapapplyService scrapapplyService;

    /**
     * 查询报废单列表
     */
    @GetMapping("/wxList")
    public TableDataInfo wxList(Scrapapply scrapapply,String status,String functionType)
    {
        startPage();
        List<Scrapapply> list = scrapapplyService.selectScrapapplyList(scrapapply, status, functionType);
        return getDataTable(list);
    }

    /**
     * 查询报废单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Scrapapply scrapapply)
    {
        startPage();
        List<Scrapapply> list = scrapapplyService.selectScrapapplyList(scrapapply);
        return getDataTable(list);
    }

    /**
     * 导出报废单列表
     */
    @PreAuthorize("@ss.hasPermi('produce:scrapapply:export')")
    @Log(title = "报废单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Scrapapply scrapapply)
    {
        List<Scrapapply> list = scrapapplyService.selectScrapapplyList(scrapapply);
        ExcelUtil<Scrapapply> util = new ExcelUtil<Scrapapply>(Scrapapply.class);
        return util.exportExcel(list, "scrapapply");
    }

    /**
     * 获取报废单详细信息
     */
    @PreAuthorize("@ss.hasPermi('produce:scrapapply:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(scrapapplyService.selectScrapapplyById(guid));
    }

    /**
     * 新增报废单
     */
    @PreAuthorize("@ss.hasPermi('produce:scrapapply:add')")
    @Log(title = "报废单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Scrapapply scrapapply)
    {
        return toAjax(scrapapplyService.insertScrapapply(scrapapply));
    }

    /**
     * 修改报废单
     */
    @PreAuthorize("@ss.hasPermi('produce:scrapapply:edit')")
    @Log(title = "报废单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Scrapapply scrapapply)
    {
        return toAjax(scrapapplyService.updateScrapapply(scrapapply));
    }

    /**
     * 删除报废单
     */
    @PreAuthorize("@ss.hasPermi('produce:scrapapply:remove')")
    @Log(title = "报废单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(scrapapplyService.deleteScrapapplyByIds(guids));
    }

    /**
     * 发起
     */
    @Log(title = "发起", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Scrapapply scrapapply, String fileIds)
    {
        return scrapapplyService.save(scrapapply, fileIds);
    }

    @Log(title = "审批", businessType = BusinessType.OTHER)
    @PostMapping("/approval")
    public AjaxResult approval(Long taskid,Long id,String opinion,@RequestParam(value="fileIds",required = false)String imgids){
        return scrapapplyService.approval(id, imgids, opinion, taskid);
    }

    @Log(title = "拒绝", businessType = BusinessType.OTHER)
    @PostMapping("/refuse")
    public AjaxResult refuse(Long taskid,Long id,String opinion,String fileIds,Long refuseNodeid,Long backUserid){
        return scrapapplyService.refuse(id, fileIds, opinion, taskid,refuseNodeid,backUserid);
    }

    @Log(title = "报废出库", businessType = BusinessType.INSERT)
    @PostMapping("/scrapWhout")
    public AjaxResult scrapWhout(@RequestBody Whoutform whoutform, Long taskid,Long id,String opinion,String fileIds)
    {
        return scrapapplyService.scrapWhout(whoutform, taskid, id, opinion, fileIds);
    }
}
